<%@ page language="java" contentType="text/html;" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html>
<head>
<jsp:include page="../inc.jsp"></jsp:include>
<title>切位预定</title>
<link rel="stylesheet" type="text/css" href="${ctx}/css/qwBook.css"/>
 
</head>
<body>
<jsp:include page="../head.jsp"></jsp:include>
	<div class="content">
			<div class="cHeader">
				<img src="${ctx}/image/book/green.gif"/><span>航班信息</span>
			</div>
			<div class="cContent">
				<div class="ccHeader" id="itineraryName">
				</div>
				<table class="tableInf" border="1" id="tbl_flights">
					<thead>
						<tr>
							<td style="width:51px">序号</td>
							<td style="width:105px">航班号</td>
							<td style="width:105px">舱位</td>
							<td style="width:584px">行程</td>
							<td style="width:103px">出发时刻</td>
							<td style="width:103px">到达时刻</td>
							<td style="width:103px">座位数</td>
							<td style="width:103px">总班数</td>
						</tr>
					</thead>
				</table>
				<div class="priceBox">
					<p class="price">总价：￥<span id="totalPrice"></span>&nbsp;&nbsp;&nbsp;押金：￥<span id="deposit"></span></p>
					<p class="timeLimit">支付时限：<span>审核通过后24小时&nbsp;&nbsp;&nbsp;</span>最晚出票时间:<span>起飞前两天</span></p>
					<p class="operation">
						<button class="blueBtn yellow" onclick="confirmBooking(this);">提交订单</button>
						<button class="blueBtn" onclick="javascript:history.go(-1);">重新搜索</button>
					</p>
				</div>
			</div>
		</div>
	

	<span id="flights" style="display: none;">${flights }</span>
	
<script type="text/javascript">
function confirmBooking(theBtn){
	var jBtn = $(theBtn);
	jBtn.attr("disabled",true).css("background-color","#808080");
	progressLoad(); 

	var orderInfo = JSON.parse('${bookingInfoJsonString}');
 
	$.ajax({
		type:'post',
		url:'${ctx}/order/createQw',
		contentType:'application/json;charset=utf-8',
		data:JSON.stringify(orderInfo),
		dataType:'json',
		success:function(data){
			progressClose();
			if(data.success){
				layer.alert(data.msg,{skin:'layui-layer-lan',title: ['系统提示', 'background-color:#00B2EE; color:#fff;'],closeBtn: 0}, function(index){
					enableSubmit(jBtn);
					delete orderInfo;
					delete BOOKINGPAGEVARS.bookingInfoFromSearchingPage;
					window.location.href="${ctx}/np/contractQuery?t="+Math.random();
				    layer.close(index);
				});
			}
			else{
				layer.alert(data.msg);
				enableSubmit(jBtn);
			}
		},
		error:function(msg){
			layer.alert("请检查您的网络连接，然后重试！");
			enableSubmit(jBtn);
		}
	}); 
}
  
function enableSubmit(jButton){
	jButton.attr("disabled",false).css("background-color","#FF6600");
	progressClose();
}
function initPage(b){
	$("#itineraryName").html(b.deptAirport+"-"+b.arrAirport);
	$("#totalPrice").html(b.totalPrice);
	$("#deposit").html(b.deposit); 
	$("#tbl_flights").append("<tr>"
		+"<td>1</td>"
		+"<td class='deptFlight'>"+b.deptFlight+"</td>"
		+"<td class='seatClass'>"+CommonConverter.toFlightCabinTypeStr(b.seatClass)+"</td>"
		+"<td class='deptAirportcode'>"+b.deptAirport+"（"+b.deptAirportcode+"）"+"-"+b.arrAirport+"（"+b.arrAirportcode+"）</td>"
		+"<td  class='deptStarttime'>"+CommonConverter.formatFlightTime(b.deptStarttime)+"</td>"
		+"<td class='deptEndtime'>"+CommonConverter.formatFlightTime(b.deptEndtime) + (b.deptIntervalday>0?("(+"+b.deptIntervalday+")"):"")+"</td>"
		+"<td class='seatCount' rowspan='2'><span id='seatCount'>"+b.seatCount+"</span></td>"
		+"<td rowspan='2'><a href='##' onclick='showFlights()' style='color:#f99001;text-decoration:underline;'>"+b.flightCount+"</a></td>"
		+"</tr>");
	$("#tbl_flights").append("<tr>"
			+"<td>2</td>"
			+"<td class='deptFlight'>"+b.arrFlight+"</td>"
			+"<td class='seatClass'>"+CommonConverter.toFlightCabinTypeStr(b.seatClass)+"</td>"
			+"<td class='deptAirportcode'>"+b.arrAirport+"（"+b.arrAirportcode+"）-"+b.deptAirport+"（"+b.deptAirportcode+"）</td>"
			+"<td class='deptStarttime'>"+CommonConverter.formatFlightTime(b.arrStarttime)+"</td>"
			+"<td class='deptEndtime'>"+CommonConverter.formatFlightTime(b.arrEndtime) + (b.arrIntervalday>0?("(+"+b.arrIntervalday+")"):"")+"</td>"
			+"</tr>");
	$("#adultCount").focus().select();
}
function showFlights(){
	layer.open({
		  type: 2,
		  title: '航班信息',
		  shadeClose: true,
		  shade: 0.1,
		  area: ['680px', '480px'],
		  content: '${ctx}/np/showFlights' //iframe的url
		}); 
}
var BOOKINGPAGEVARS={"bookingInfoFromSearchingPage":{}};
$(function(){
	BOOKINGPAGEVARS.bookingInfoFromSearchingPage = JSON.parse('${contract}');
	initPage(BOOKINGPAGEVARS.bookingInfoFromSearchingPage);
});
</script>
<jsp:include page="../footer.jsp"></jsp:include>
</body>
</html>